package com.jiusit.task;

import java.sql.Connection;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.webbuilder.utils.DateUtil;
import com.webbuilder.utils.DbUtil;


public class DelPriceInfoTask implements Job{

	@Override
	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		System.out.println("删除7天前产品价格数据任务,开始" + new Date());
		
		Connection conn = null;	
		Statement delete_day_st = null;
		Statement delete_minute_st = null;
		try{
			conn = DbUtil.getConnection();
			conn.setAutoCommit(false);
			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			Date currDate = new Date();			
			Date sevenDate = DateUtil.dateAdd(DateUtil.DAY, -3, currDate);			
			String sevenDateStr = df.format(sevenDate);
			
			String DelDaySql = "delete from wjy_prodata_by_hour where create_time < '"+sevenDateStr+"'";
			String DelMinuteSql = "delete from wjy_prodata_by_minute where create_time < '"+sevenDateStr+"'";
			
			delete_day_st = conn.createStatement();
			delete_day_st.executeUpdate(DelDaySql);
			
			delete_minute_st = conn.createStatement();
			delete_minute_st.executeUpdate(DelMinuteSql);
			
		}catch(Exception e){
			DbUtil.closeConnection(conn,true);
			e.printStackTrace();
		}finally{
			DbUtil.closeStatement(delete_day_st);
			DbUtil.closeStatement(delete_minute_st);
			DbUtil.closeConnection(conn, false);
		}
		System.out.println("删除7天前产品价格数据任务,结束" + new Date());
	}
	
}
